package cn.sll.org.dto;

import cn.sll.base.util.MD5Utils;
import cn.sll.base.util.StrUtils;
import cn.sll.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class SmsRegisterDto {

    @NotBlank(message = "电话号码不能为空")
    //电话号码
    private String phone;

    @NotBlank(message = "短信验证码不能为空")
    //短信验证码
    private String smsPhoneValue;

    @NotBlank(message = "密码不能为空")
    //密码
    private String password;

    @NotBlank(message = "确认密码不能为空")
    //确认密码
    private String passwordRepeat;

    public User getUser() {
        String salt = StrUtils.getComplexRandomString(32);
        String password = MD5Utils.encrypByMd5(salt + getPassword());
        return User.builder()
                .username(this.phone)
                .phone(phone)
                .salt(salt)
                .password(password)
                .state(1)
                .createtime(new Date())
                .build();
    }

}
